package com.gx.smart.building.ui.repair.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemRepairRecordLayoutBinding;
import com.gx.smart.building.ui.repair.common.CommonHelper;
import com.gx.smart.lib.http.api.response.WorkOrder;

/**
 * @author xiaosy
 * @create 2020/5/8
 * @Describe 维修详情
 **/
public class RepairRecordAdapter extends BaseAdapter<WorkOrder, RepairRecordAdapter.ViewHolder> {
    public RepairRecordAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_repair_record_layout;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemRepairRecordLayoutBinding binding = ItemRepairRecordLayoutBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, WorkOrder item, int position) {
        holder.binding.orderCode.setText(item.getOrderCode());
        String status = CommonHelper.getStatus(item.getStatus());
        holder.binding.status.setText(status);
        holder.binding.description.setText(item.getDescription());
        String source = item.getOrderSourceName() == null || item.getOrderSourceName().isEmpty()
                ? "--" : item.getOrderSourceName();
        holder.binding.orderSourceName.setText("来源:" + source);
        holder.binding.releaseUserName.setText("创建人:" + item.getCreateUserName());
        String createTime = TimeUtils.millis2String(item.getCreateTime(), "yyyy-MM-dd HH:mm:ss");
        holder.binding.createTime.setText("创建时间:" + createTime);

    }

    protected static class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemRepairRecordLayoutBinding binding;

        public ViewHolder(ItemRepairRecordLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
